package ru.stool.erp.grants.impl;

import java.util.ArrayList;
import java.util.List;

import ru.stool.erp.StoolERPConst;
import ru.stool.erp.grants.EmployeeGrantsCalculator;
import ru.stool.erp.model.entities.EmployeeEntity;
import ru.stool.erp.model.entities.EmployeeGroupEntity;

public class DefaultEmployeeGrantsCalculator implements EmployeeGrantsCalculator{

	@Override
	public List<String> calculate(EmployeeEntity emp) {
		if(emp==null)
			throw new IllegalArgumentException("EmployeeEntity cannot be null");
		
		List<EmployeeGroupEntity> groups=emp.getGroups();
		List<String> ret=new ArrayList<String>();
		
		if(groups==null || groups.size()==0){
			ret.add(StoolERPConst.ROLE_WITHOUTROLE_NAME);
		}else{
			for(EmployeeGroupEntity group: groups){
				ret.addAll(group.getGrants());
			}
		}
		
		
		return ret;
	}

	
}
